﻿using System;
using UnityEngine;
using UnityEngine.UI;

public class UnityGameObject
{
    public GameObject gameObj = null;

    internal T GetComponent<T>()
    {
        throw new NotImplementedException();
    }

    /// <summary>
    /// 创建GameObject
    /// </summary>
    /// <param name="prefabName"></param>
    /// <param name="spawnPos"></param>
    /// <param name="rotation"></param>
    /// <returns></returns>
    public GameObject Instantiate(string prefabName, Vector3 spawnPos, Quaternion rotation)
    {
        UnityEngine.Object objPrefab = Resources.Load(prefabName);

        gameObj = (GameObject)GameObject.Instantiate(objPrefab, spawnPos, rotation);

        return gameObj;
    }

    /// <summary>
    /// 销毁GameObject
    /// </summary>
    public void Destroy()
    {
        GameObject.Destroy(gameObj);
    }

    /// <summary>
    /// 位置相关
    /// </summary>
    
    public Transform GetTransform()
    {
        return gameObj.transform;
    }

    public void SetPosition(Vector3 position)
    {
        gameObj.transform.position = position;
    }

    public Vector3 GetPosition()
    {
        return gameObj.transform.position;
    }

    public void SetRotation(Quaternion rotation)
    {
        gameObj.transform.rotation = rotation;
    }

    public Quaternion GetRotation()
    {
        return gameObj.transform.rotation;
    }

    public void SetAnmiInteger(string name, int value)
    {
        gameObj.GetComponent<Animator>().SetInteger(name, value);
    }

    public void SetAnmiBool(string name, bool value)
    {
        gameObj.GetComponent<Animator>().SetBool(name, value);
    }

    public void SetAnmiTrigger(string name)
    {
        gameObj.GetComponent<Animator>().SetTrigger(name);
    }
    
    /// <summary>
    /// 设置渲染颜色
    /// </summary>
    /// <param name="color"></param>
    public void SetSpriteRendererColor(Color color)
    {
        gameObj.GetComponent<SpriteRenderer>().color = color;
    }

    public Color GetSpriteRendererColor()
    {
        return gameObj.GetComponent<SpriteRenderer>().color;
    }

    /// <summary>
    /// 下面是UGUI部分
    /// </summary>
    /// 
    public void Show()
    {
        gameObj.SetActive(true);
    }

    public void Hide()
    {
        gameObj.SetActive(false);
    }

    /// <summary>
    /// 获取控件
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="name"></param>
    /// <returns></returns>
    public T GetComponent<T>(string name)
    {
        return gameObj.transform.Find(name).gameObject.GetComponent<T>();
    }
}
